package kofman.test.cps;

import java.util.ArrayList;

import android.R.integer;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

public class MyItemizeOverlay extends ItemizedOverlay<OverlayItem> {
	private ArrayList<OverlayItem> overlayItems=new ArrayList<OverlayItem>();
	private Context context;
	public MyItemizeOverlay(Context context,Drawable defaultMarker) {
		super(defaultMarker);
		this.context=context;
	}
	
	public void draw(Canvas canvas, MapView Mapview, boolean shadow){
		super.draw(canvas, Mapview, shadow);
		Projection projection=Mapview.getProjection();
		for (int index = this.size()-1; index > 0; index--) {
			OverlayItem overlayItem=getItem(index);
			Point point=projection.toPixels(overlayItem.getPoint(), null);
			Paint paint=new Paint();
			paint.setColor(Color.RED);
			paint.setTextSize(13);
			canvas.drawText(overlayItem.getTitle(), point.x+10, point.y-15, paint);
			
		}
		
	}
	protected boolean onTop(int index) {
		setFocus(overlayItems.get(index));
		return super.onTap(index);
	}
	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return overlayItems.get(i);
	}

	@Override
	public int size() {
		return overlayItems.size();
	}
	public void addOverlay(OverlayItem overlayItem){
		overlayItems.add(overlayItem);
		this.populate();
	}

}
